package com.kischang.blog.web.action;

import com.kischang.blog.utils.Utils;
import com.kischang.blog.web.actionuser.RegisterAction;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

/**
 * Created by KisChang on 2015/5/31.
 * 修改配置
 */
@Component
@Scope("prototype")
public class NBAction  extends ActionSupport {
    private static final String NBACTION = "NBACTION_HHA";
    private String code;
    private boolean notPost;
    private boolean notReg;

    public NBAction() {
        notPost = PostTopicAction.getNOTPOST();
        notReg = RegisterAction.getNOTREG();
    }

    @Override
    public String execute() throws Exception {
        String oldCode = (String) ActionContext.getContext().getSession().get(NBACTION);
        if(oldCode != null && code != null && oldCode.toLowerCase().equals(code.toLowerCase())){
            PostTopicAction.setNOTPOST(notPost);
            RegisterAction.setNOTREG(notReg);
        }
        return SUCCESS;
    }
    public String view() throws Exception {
        String temp = (String) ActionContext.getContext().getSession().get(NBACTION);
        if(temp != null && !"".equals(temp)){
            return "view";
        }
        code = Utils.randomStr(2);
        ActionContext.getContext().getSession().put(NBACTION,code);
        Utils.sendMail("734615869@qq.com", "don't reply-修改系统配置",code);
        return "view";
    }

    public void setCode(String code) {
        this.code = code;
    }

    public void setNotPost(boolean notPost) {
        this.notPost = notPost;
    }

    public void setNotReg(boolean notReg) {
        this.notReg = notReg;
    }

    public boolean isNotPost() {
        return notPost;
    }

    public boolean isNotReg() {
        return notReg;
    }
}
